package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.VideoManager;
import com.itheima.domain.mongo.Video;
import com.itheima.domain.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

@RestController
public class VideoController {

    @Autowired
    private VideoManager videoManager;


    //小视频列表
    @GetMapping("/smallVideos")
    public ResponseEntity smallVideos(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize
    ) throws IOException {

        //为什么需要传递userId
        PageBeanVo pageBeanVo = videoManager.smallVideos(UserHolder.getUserId(), page, pagesize);
        return ResponseEntity.ok(pageBeanVo);
    }
    //小视频发布
    @PostMapping("/smallVideos")
    public ResponseEntity saveVideo(
        MultipartFile videoThumbnail , MultipartFile videoFile
    ) throws IOException {

        return videoManager.saveVideo(videoThumbnail , videoFile);
    }

    //关注
    @PostMapping("/smallVideos/{focusUserId}/userFocus")
    public ResponseEntity userFocus(
            @PathVariable Long focusUserId
    ) throws IOException {

        return videoManager.userFocus(focusUserId);
    }

    //取消关注
    @PostMapping("/smallVideos/{focusUserId}/userUnFocus")
    public ResponseEntity userUnFocus(
            @PathVariable Long focusUserId
    ) throws IOException {

        return videoManager.userUnFocus(focusUserId);
    }
}
